package com.ricohgag.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ricohgag.entity.UserAddress;
import com.ricohgag.mapper.UserAddressMapper;
import com.ricohgag.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 肖晖
 * @since 2018-08-25
 */
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements UserAddressService {
    @Autowired
    private UserAddressMapper userAddressMapper;

    @Override
    public List<UserAddress> selectAddressByUserId(Integer id) throws Exception{
        return userAddressMapper.selectList(new QueryWrapper<UserAddress>()
            .eq("user_id", id));

    }

    @Override
    public UserAddress selectOneById(Integer id) throws Exception{
        return userAddressMapper.selectById(id);
    }

    @Override
    public boolean update(UserAddress userAddress) throws Exception{
        int count = userAddressMapper.updateById(userAddress);
        return count > 0;
    }

    @Override
    public boolean insert(UserAddress userAddress) throws Exception{
        int count = userAddressMapper.insert(userAddress);
        return count > 0;
    }

    @Override
    public boolean delete(Integer id) throws Exception{
        int count = userAddressMapper.deleteById(id);
        return count > 0;
    }

}
